<?php

namespace app\service\im;

use app\service\im\Base;

class Chat extends Base
{
    /**
     * Describe:管理员向某个人发送消息/或者管理员已某个用户的身份发送消息给某人
     * User: TANGFEN
     */
    public function sendmsg($messages, $To_Account,$From_Account = '')
    {

        $url = $this->url . 'openim/sendmsg';
        $data = [
            'From_Account'=>$From_Account,
            'To_Account' => $To_Account,
            'MsgRandom' => $this->random, //随机数
            'CloudCustomData'=>'自定义的消息内容666',
            'MsgBody' => [
                [
                    'MsgType' => 'TIMTextElem',
                    'MsgContent' => [
                        'Text' => $messages
                    ],
                ]
            ]
        ];

        return $this->common($url, $data);
    }

    /**
     * Describe:批量发送消息给指定用户
     * User: TANGFEN
     * $messages 消息内容
     * $userIds 用户id [32,43]
     */
    public function batchsendmsg($messages, $userIds)
    {

        $url = $this->url . 'openim/batchsendmsg';
        $data = [
            'To_Account' => $userIds,
            'MsgRandom' => $this->random, //随机数
            'MsgBody' => [
                [
                    'MsgType' => 'TIMTextElem',
                    'MsgContent' => [
                        'Text' => $messages
                    ],
                ]
            ]
        ];
        return $this->common($url, $data);
    }


}